$(function () {
    let contactId = localStorage.getItem("contactId");
    findByCompanyId(contactId);
});

function findByCompanyId(id) {
    $.ajax({
        url: '/back/company/findByContactId',
        data: {id: id},
        type: 'get',
        dataType: 'json',
        success: function (data) {
            setCompanyData(data.companyContactModel);//需要给数据  把后台数据拿到
        }
    })
}

function setCompanyData(data) {
    console.log(data);
    $("#contactId").val(data.id);
    $("#companyName").val(data.companyName);
    $("#adress").val(data.adress);
    $("#phone").val(data.phone);
    $("#email").val(data.email);
    $("#fax").val(data.fax);
    $("#qrCode").val(data.qrCode);
}

function contactEdit() {
    let forData = new FormData();
    forData.append("contactId", $("#contactId").val());
    forData.append("companyName", $("#companyName").val());
    forData.append("adress", $("#adress").val());
    forData.append("phone", $("#phone").val());
    forData.append("email", $("#email").val());
    forData.append("fax", $("#fax").val());
    forData.append("qrCode", $("#qrCode")[0].files[0]);//文件取值
    $.ajax({
        url: '/back/company/contactEdit',
        data: forData,
        contentType: false,
        processData: false,
        type: 'post',
        dataType: 'json',
        success: function (data) {
            if (data.result === 1) {
                alert("提交成功");
                $("#right").load('/back/company/contactManage.html');
            } else {
                alert("提交失败")
            }
        }
    })
}
function cancelContactEdit() {
    $("#right").load('/back/company/contactManage.html');
}